import java.util.Collections;

public class ABTree {
	
	public static void main(String[] args) {
		ABTree tree = new ABTree();
		for (int i = 1; i < 19; ++i) {
			tree.insert(i);
			tree.print();
		}
		for (int i = 5; i < 15; ++i) {
			tree.remove(i);
			tree.print();
		}
		for (int i = 9; i < 12; ++i) {
			tree.insert(i);
			tree.print();
		}
	}

	ABTreeRootNode root = new ABTreeRootNode();
	
	void insert(int value) {
		if (root.children.size() < 2) {
			root.children.add(new ABTreeLeaf(root, value));
			Collections.sort(root.children);
		} else {
			root.insert(value);
		}
	}

	void remove(int value) {
		root.remove(value);
	}

	void print() {
		root.print();
		System.out.println();
	}
}
